package com.hsqn.controller;

import com.hsqn.entity.HealthAndSafety;
import com.hsqn.entity.Result;
import com.hsqn.entity.WorkOrder;
import com.hsqn.service.WorkOrderService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RequestMapping("/workOrder")
@RestController
public class WorkOrderController {
    @Autowired
    private WorkOrderService workOrderService;

    /**
    * 添加工单
     */
    @PostMapping
    @Operation(
            summary = "添加工单",
            description = "添加工单",
            responses = {
                    @ApiResponse(responseCode = "200", description = "添加成功",
                            content = @Content(schema = @Schema(implementation = HealthAndSafety.class))),
                    @ApiResponse(responseCode = "404", description = "添加失败")
            }
    )
    public Result insertWorkOrder(@RequestBody WorkOrder workOrder) {
        workOrderService.insertWorkOrder(workOrder);
        return Result.success();
    }

    /**
     * 修改执行人
     */
    @PutMapping
    @Operation(
            summary = "修改执行人",
            description = "修改执行人",
            responses = {
                    @ApiResponse(responseCode = "200", description = "修改成功",
                            content = @Content(schema = @Schema(implementation = HealthAndSafety.class))),
                    @ApiResponse(responseCode = "404", description = "修改失败")
            }
    )
    public Result updateWorkOrder(@RequestBody WorkOrder workOrder) {
        workOrderService.updateAssignInfo(workOrder);
        return Result.success();
    }

    @PutMapping("/{orderStatus}")
    @Operation(
            summary = "修改工单状态",
            description = "修改工单状态",
            responses = {
                    @ApiResponse(responseCode = "200", description = "修改成功",
                            content = @Content(schema = @Schema(implementation = HealthAndSafety.class))),
                    @ApiResponse(responseCode = "404", description = "修改失败")
            }
    )
    public Result updateCompleteInfo(@PathVariable Integer orderStatus) {
        workOrderService.updateCompleteInfo(orderStatus);
        return Result.success();
    }


}
